// 存储警告数据
let warnings = [
    {id: 1, title: "游戏崩溃风险", content: "此MOD可能导致游戏在特定场景下崩溃", type: "critical"},
    {id: 2, title: "性能影响", content: "使用此MOD可能导致游戏帧率下降", type: "medium"},
    {id: 3, title: "兼容性问题", content: "与最新版本游戏可能存在兼容性问题", type: "medium"},
    {id: 4, title: "新功能提示", content: "此MOD添加了新的游戏机制", type: "info"}
];

let currentWarningId = null;

// 页面加载时显示所有警告
document.addEventListener('DOMContentLoaded', displayWarnings);

// 显示所有警告
function displayWarnings(filteredWarnings = null) {
    const tableBody = document.querySelector('#warningTable tbody');
    tableBody.innerHTML = '';

    const dataToDisplay = filteredWarnings || warnings;

    if (dataToDisplay.length === 0) {
        const row = document.createElement('tr');
        row.innerHTML = `<td colspan="5" style="text-align: center;">没有找到警告</td>`;
        tableBody.appendChild(row);
        return;
    }

    dataToDisplay.forEach(warning => {
        const row = document.createElement('tr');
        row.innerHTML = `
                    <td>${warning.id}</td>
                    <td>${warning.title}</td>
                    <td>${warning.content}</td>
                    <td><span class="status status-${warning.type}">${getTypeName(warning.type)}</span></td>
                    <td>
                        <button class="edit" onclick="editWarning(${warning.id})">编辑</button>
                        <button class="delete" onclick="openDeleteModal(${warning.id})">删除</button>
                    </td>
                `;
        tableBody.appendChild(row);
    });
}

// 获取类型的显示名称
function getTypeName(type) {
    switch (type) {
        case 'critical':
            return '严重';
        case 'medium':
            return '中等';
        case 'minor':
            return '轻微';
        case 'info':
            return '信息';
        default:
            return type;
    }
}


// 搜索警告
function searchWarnings() {
    const searchTerm = document.getElementById('search').value.toLowerCase();
    if (!searchTerm) {
        displayWarnings();
        return;
    }

    const filtered = warnings.filter(warning =>
        warning.title.toLowerCase().includes(searchTerm) ||
        warning.content.toLowerCase().includes(searchTerm)
    );

    displayWarnings(filtered);
}

$(document).ready(function () {
    $('#menu-toggle').click(function () {
        $('#mobile-menu').slideToggle();
    });
});